package edu.hpu.service;

import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;

/**
 * @Author 三分恶
 * @Date 2020/1/11
 * @Description
 */
@Service
public class MethodService {
    //示访问该方法需要 ADMIN 角色
    @Secured("ROLE ADMIN")
    public String admin () {
        return "hello admin ";
    }

    //访问该方法既需要ADMIN角色又需要USER角色
    @PreAuthorize("hasRole ('ADMIN') and hasRole ('USER ')")
        public String user(){
        return "Hello User";
    }

    //访问该方法需要ADMIN 或 USER角色
    @PreAuthorize("hasAnyRole('ADMIN','USER')")
    public String any(){
        return "Hello Every One";
    }

}
